package com.aaa.controller;

import com.aaa.entity.Emp;
import com.aaa.service.impl.EmpServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@CrossOrigin
@Controller
@RequestMapping("emp")
public class EmpController {
    @Resource
    EmpServiceImpl empService;
    @RequestMapping("login")
    public String login(String eusername, String epassword, HttpSession session){
        Map<String,Object> list=empService.login(eusername,epassword);
        if(null!=list){
            session.setAttribute("login",list);
            return "main";
        }
        return "index";
    }
    @RequestMapping("list")
    @ResponseBody
    public List<Emp> list(){
        return empService.list();
    }
    @RequestMapping("save")
    @ResponseBody
    public Boolean save(Emp emp){
        return empService.save(emp);
    }
    @RequestMapping("remove")
    @ResponseBody
    public Boolean remove(Integer eid){
        return empService.removeById(eid);
    }
    @RequestMapping("update")
    @ResponseBody
    public Boolean update(Emp emp){
        return empService.updateById(emp);
    }
    @RequestMapping("listWrapper")
    @ResponseBody
    public List<Emp> listWrapper(String eusername){
        //按条件查询
        QueryWrapper<Emp> wrapper=new QueryWrapper<>();
        wrapper.eq("eusername",eusername);
        return empService.list(wrapper);
    }
    @RequestMapping("select")
    @ResponseBody
    public List<Emp> select(Integer eid){
        return empService.select(eid);
    }
    @RequestMapping("select2")
    @ResponseBody
    public List<Emp> select2(){
        return empService.select2();
    }
    @RequestMapping("select3")
    @ResponseBody
    public List<Emp> select3(String eusername){
        return empService.select3(eusername);
    }
}
